<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Admincp extends Admin
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //获取菜单
        $map['display'] = 1;

        //检查权限,如果是超级管理员 ，则显示所有菜单
        // $roleid = session('roleid');
        // if($roleid != 1){
        //     //取出权限中的menu_id
        //     $priv_list = db('admin_role_priv')->where('roleid='.$roleid)->field('menuid')->select();

        //     $menu_ids = '';
        //     if($priv_list){
        //         foreach ($priv_list as $v){
        //             $menu_ids .= $menu_ids ? ','.$v['menuid'] : $v['menuid'];
        //         }
        //         $map['id'] = array('in', $menu_ids);
        //     }
        // }
        $result = db('admin_menu')->where($map)->order('listorder,id')->field('id,listorder,name,icon,c,a,parentid')->select();
        
        //这里可以做缓存
        $menu=list_to_tree($result,'id','parentid','_child');
        $this->assign('menu', $menu);
        //$this->display();

        return $this->fetch();
    }

    public function welcome(){
        return $this->fetch();
    }
}
